<template>
    签名一个信息：<input type="text" v-model="waitToSign" />
        <button @click="signMsg">Sign</button>
    <p>得到结果: {{SinedMsg}} </p>  
    验证一个签名:
        签名者:<input type="text" v-model="sinerAddress"/>
        内容: <input type="text" v-model="waitToSign"/>
        签名: <input type="text" v-model="waitToVertify"/>
        <button @click="checkSign">check</button>
        <p>验证消息为签名者:{{checkResult}}签发的消息</p>
    </template>
<script setup lang="ts">
// todo 以下板块待封装
import {ethers} from 'ethers'
import {ref} from 'vue'
let SinedMsg=ref()
let waitToSign=ref("");

let waitToVertify=ref("")
let sinerAddress=ref("")
let checkResult=ref("")

 function signMsg(){
const provider=new ethers.BrowserProvider(window.ethereum)
let pro=provider.getSigner()

// 以上板块待封装
pro.signMessage(waitToSign.value).then((rs)=>{
    SinedMsg.value=rs
    waitToVertify.value=rs
    
})
pro.getAddress().then((rs)=>{
    sinerAddress.value=rs

    console.log(rs)
})
// pro.getAddress().then((rs)=>{
//     sinerAddress.value=rs[0]
// })
}
// 
function checkSign(){
    checkResult.value = ethers.utils.verifyMessage(waitToSign.value,waitToVertify.value)
}

</script>